/*
 * This file is part of JContextFree.
 *
 * JContextFree is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JContextFree is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JContextFree.  If not, see <http://www.gnu.org/licenses/>.
 */

package it.enricod.jcontextfree.gui.impl;

import it.enricod.jcontextfree.gui.IMainFrame;
import it.enricod.jcontextfree.gui.IToolBar;
import it.enricod.jcontextfree.gui.events.DrawProgramEvent;
import it.enricod.jcontextfree.gui.events.LoadProgramCommandEvent;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JToolBar;

import org.apache.log4j.Logger;
import org.bushe.swing.event.EventBus;

public class ToolBar implements IToolBar {

	private Action loadAction;
	private Action drawAction;
	private JToolBar toolBar;
	private JButton loadBtn;
	private JButton drawBtn;
	private IMainFrame mainFrame;
	private Logger logger = Logger.getLogger("ToolBar");

	public ToolBar(IMainFrame mainFrame) {
		this.mainFrame = mainFrame;
		initGui();
	}

	private void initGui() {

		loadAction = new AbstractAction("Carica programma") {

			public void actionPerformed(ActionEvent arg0) {
				EventBus.publish(new LoadProgramCommandEvent());
			}
		};
		loadBtn = new JButton(loadAction);

		drawAction = new AbstractAction("Disegna") {

			public void actionPerformed(ActionEvent arg0) {
				EventBus.publish(new DrawProgramEvent(mainFrame.getProgramPanel().getProgramAsText()));
			}
		};
		drawBtn = new JButton(drawAction);

		toolBar = new JToolBar();
		toolBar.add(loadBtn);
		toolBar.add(drawBtn);
	}

	public JToolBar getToolBar() {
		return toolBar;
	}
}
